import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:qilo/core/constants/app_icons.dart';
import '../../../core/providers/global_state_coordinator.dart';

class ProfileHeaderSection extends StatelessWidget {
  final VoidCallback onSettingsTap;

  const ProfileHeaderSection({super.key, required this.onSettingsTap});

  @override
  Widget build(BuildContext context) {
    return Consumer<GlobalStateCoordinator>(
      builder: (context, coordinator, child) {
        final isLoggedIn = coordinator.isLoggedIn;
        final userInfo = coordinator.currentUser;

        return Column(
          children: [
            SizedBox(
              width: double.infinity,
              child: Stack(
                children: [
                  SizedBox(
                    width: double.infinity,
                    height: (355.0 / 375.0) * MediaQuery.of(context).size.width,
                    child: Stack(
                      alignment: Alignment.center,
                      children: [
                        Image.asset("assets/images/my-top.png"),
                        Transform.translate(
                          offset: Offset(1.w, 25.h),
                          child: Container(
                            width: 90.w,
                            height: 90.w,
                            decoration: BoxDecoration(
                              shape: BoxShape.circle,
                              color: isLoggedIn ? null : Colors.white,
                              image:
                                  isLoggedIn &&
                                          userInfo?.avatar.isNotEmpty == true
                                      ? DecorationImage(
                                        image: AssetImage(userInfo!.avatar),
                                        fit: BoxFit.cover,
                                      )
                                      : null,
                            ),
                            child:
                                !isLoggedIn
                                    ? GestureDetector(
                                      onTap: () {
                                        Navigator.pushNamed(context, '/login');
                                      },
                                      child: Icon(
                                        MyIcons.iconPeople,
                                        size: 50.w,
                                        color: Colors.grey[600],
                                      ),
                                    )
                                    : null,
                          ),
                        ),
                      ],
                    ),
                  ),

                  if (isLoggedIn)
                    Positioned(
                      top: MediaQuery.of(context).padding.top,
                      right: 16.w,
                      child: GestureDetector(
                        onTap: onSettingsTap,
                        child: Icon(
                          Icons.settings,
                          color: Colors.white,
                          size: 24.w,
                        ),
                      ),
                    ),
                ],
              ),
            ),

            Text(
              isLoggedIn ? (userInfo?.userName ?? 'User') : 'MINA PRATT',
              style: TextStyle(
                fontSize: 20.sp,
                fontFamily: 'Porter Sans Block',
                fontWeight: FontWeight.bold,
                color: Colors.white,
              ),
            ),
          ],
        );
      },
    );
  }
}
